package com.ruoyi.business.pay.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.pay.domain.ThirdPaymentAgency;
import com.ruoyi.business.pay.service.IThirdPaymentAgencyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 非银行第三方支付机构（拿到支付许可证的）Controller
 * 
 * @author ruoyi
 * @date 2022-11-11
 */
@Controller
@RequestMapping("/business/agency")
public class ThirdPaymentAgencyController extends BaseController
{
    private String prefix = "business/agency";

    @Autowired
    private IThirdPaymentAgencyService thirdPaymentAgencyService;

    @RequiresPermissions("business:agency:view")
    @GetMapping()
    public String agency()
    {
        return prefix + "/agency";
    }

    /**
     * 查询非银行第三方支付机构（拿到支付许可证的）列表
     */
    @RequiresPermissions("business:agency:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ThirdPaymentAgency thirdPaymentAgency)
    {
        startPage();
        List<ThirdPaymentAgency> list = thirdPaymentAgencyService.selectThirdPaymentAgencyList(thirdPaymentAgency);
        return getDataTable(list);
    }

    /**
     * 导出非银行第三方支付机构（拿到支付许可证的）列表
     */
    @RequiresPermissions("business:agency:export")
    @Log(title = "非银行第三方支付机构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ThirdPaymentAgency thirdPaymentAgency)
    {
        List<ThirdPaymentAgency> list = thirdPaymentAgencyService.selectThirdPaymentAgencyList(thirdPaymentAgency);
        ExcelUtil<ThirdPaymentAgency> util = new ExcelUtil<ThirdPaymentAgency>(ThirdPaymentAgency.class);
        return util.exportExcel(list, "非银行第三方支付机构数据");
    }

    /**
     * 新增非银行第三方支付机构（拿到支付许可证的）
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存非银行第三方支付机构（拿到支付许可证的）
     */
    @RequiresPermissions("business:agency:add")
    @Log(title = "非银行第三方支付机构（拿到支付许可证的）", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ThirdPaymentAgency thirdPaymentAgency)
    {
        return toAjax(thirdPaymentAgencyService.insertThirdPaymentAgency(thirdPaymentAgency));
    }

    /**
     * 修改非银行第三方支付机构（拿到支付许可证的）
     */
    @RequiresPermissions("business:agency:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ThirdPaymentAgency thirdPaymentAgency = thirdPaymentAgencyService.selectThirdPaymentAgencyById(id);
        mmap.put("thirdPaymentAgency", thirdPaymentAgency);
        return prefix + "/edit";
    }

    /**
     * 修改保存非银行第三方支付机构（拿到支付许可证的）
     */
    @RequiresPermissions("business:agency:edit")
    @Log(title = "非银行第三方支付机构（拿到支付许可证的）", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ThirdPaymentAgency thirdPaymentAgency)
    {
        return toAjax(thirdPaymentAgencyService.updateThirdPaymentAgency(thirdPaymentAgency));
    }

    /**
     * 删除非银行第三方支付机构（拿到支付许可证的） TODO lsl 不允许删除
     */
    /*@RequiresPermissions("business:agency:remove")
    @Log(title = "非银行第三方支付机构（拿到支付许可证的）", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(thirdPaymentAgencyService.deleteThirdPaymentAgencyByIds(ids));
    }*/
}
